package com.example;

import com.example.pojo.User;
import com.example.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@SpringBootTest
public class MYBatisPlusService {

     //引用servies的方法
    @Autowired
    private UserService userService;

    /**
     * 查询总条数
     */
    @Test
    public void SelectCount(){
         long count = userService.count();
        System.out.println("count"+count);

    }


    /**
     * 根据id删除
     */
    @Test
    public void removeById(){
        boolean count = userService.removeById(3L);
        System.out.println("count"+count);
        if (count){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }

    }



    /**
     * 批量添加
     */
    @Test
    public void removeById1(){
        List<User> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setName("闫文超"+i);
            user.setAge(10+i);
            user.setEmail("757631644"+i+i+1);
        list.add(user);
        }

        boolean count = userService.saveBatch(list);
        System.out.println("count"+count);
        if (count){
            System.out.println("批量添加成功");
        }else {
            System.out.println("批量添加失败");
        }

    }
}
